const db = require('../util/db')

class Student {
  async list(ctx) {
    console.log(1)
    let rs = await db('select * from student')
    ctx.body = rs;
  }

  async add(ctx) {
    console.log(1)
    let params = ctx.request.body;
    console.log(params)
    let rs = await db('insert into  student set ? ', params)
    ctx.body = rs;
  }

  async remove(ctx) {
    let {id}= ctx.request.body;
    let result = await db('delete from student where id = ? ',id);
    ctx.body = result;
  }

  async update(ctx){
    let {id,age} = ctx.request.body;
    let result = await db('update student set age = ?  where id = ?',[age,id])
    ctx.body = result;

  }


}

module.exports = new Student();